package com.xuan.config;

import com.xuan.handler.LoginHandler;
import com.xuan.handler.RefreshTokenHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;


@Configuration
@Slf4j(topic = "WebConfig")
public class WebConfig implements WebMvcConfigurer {
    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginHandler(stringRedisTemplate))
                .addPathPatterns("/**")
                .excludePathPatterns("/user/login", "/user/register", "/captcha").order(1);
        registry.addInterceptor(new RefreshTokenHandler(stringRedisTemplate))
                .addPathPatterns("/**").excludePathPatterns("/user/login", "/user/register", "/captcha")
                .order(2);
    }
}
